/**
 * desc: 日志文件设置
 * User: zhitao.guo@leweipai.cn
 * Date: 2020/12/30
 * Time: 11:18
 */
const path = require('path');
const log4js = require('koa-log4');
log4js.configure({
    appenders: {
        errorLogs: {
            type: 'file',
            filename: 'logs/error/file.log',
            maxLogSize: 10485760,
            backups: 20,
            compress: true
        },
        justErrors: {
            type: 'logLevelFilter', // 过滤指定level的文件
            appender: 'errorLogs',  // appender
            level: 'error'  // 过滤得到error以上的日志
        },
        access: {
            type: 'dateFile',
            pattern: '-yyyy-MM-dd.log', //生成文件的规则
            filename: path.join('logs/', 'access.log'), //生成文件名
            maxLogSize: 10485760, // 10mb,日志文件大小,超过该size则自动创建新的日志文件
            backups: 20,  // 仅保留最新的20个日志文件
            compress: true,//  超过maxLogSize,压缩代码
            level: 'trace',
            daysToKeep: 30,
            maxLevel: 'info'
        },
        console: {
            type: 'console',
            layout: {
                type: 'colored'
            }
        }
    },
    categories: {
        default: { appenders: ['console', 'access', 'justErrors'], level: 'info' },
        err: { appenders: ['errorLogs'], level: 'error' },
    }
});

exports.accessLogger = () => log4js.koaLogger(log4js.getLogger('access'));
exports.logger = log4js.getLogger('application');

